package com.work.straighttalk.presenter;

import com.work.straighttalk.model.LoginMImpl;
import com.work.straighttalk.model.i.LoginMI;
import com.work.straighttalk.model.i.OnLoginFinishedListener;
import com.work.straighttalk.presenter.i.LoginPI;
import com.work.straighttalk.ui.i.LoginVI;

import cn.bmob.v3.exception.BmobException;

/**
 * Created by dllo on 16/3/4.
 */
public class LoginPImpl implements LoginPI, OnLoginFinishedListener {
    private LoginVI loginVI;
    private LoginMI loginMI;

    public LoginPImpl(LoginVI loginVI) {
        this.loginVI = loginVI;
        this.loginMI = new LoginMImpl();
    }

    @Override
    public void validateLogin(String username, String password) {
        if (loginVI != null) {
            loginMI.loginIn(username, password, this);
        }
    }

    @Override
    public void onDestroy() {
        loginVI = null;

    }

    @Override
    public void onError(BmobException e) {
        if (loginVI != null){
            loginVI.error(e);
        }

    }

    @Override
    public void onSuccess() {
        if (loginVI != null){
            loginVI.toMainActivity();
        }
    }
}
